﻿<Window x:Class="Mar3ek.ColorHatTimeTracker.Windows.TimeRecordsBrowser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:viewModels="clr-namespace:Mar3ek.ColorHatTimeTracker.ViewModels"
        xmlns:colorhatNet="clr-namespace:ColorhatNet;assembly=ColorhatNet"
        Title="Time entries" Height="600" Width="850" WindowStartupLocation="CenterScreen">
    <Window.DataContext>
        <viewModels:TimeRecordsBrowserViewModel />
    </Window.DataContext>
    <Window.Resources>
        <Style TargetType="{x:Type Label}">
            <Style.Setters>
                <Setter Property="Padding" Value="0,0,0,0"></Setter>
            </Style.Setters>
        </Style>
    </Window.Resources>
    <Grid>
        <GroupBox Header="Filters" Margin="10,10,9.6,0" VerticalAlignment="Top" Height="78">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <Label Content="Start date:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
                <DatePicker HorizontalAlignment="Left" Margin="10,31,0,0" VerticalAlignment="Top" Width="135" SelectedDate="{Binding StartingDate}"/>
                <Label Content="End date:" HorizontalAlignment="Left" Margin="150,10,0,0" VerticalAlignment="Top"/>
                <DatePicker HorizontalAlignment="Left" Margin="150,31,0,0" VerticalAlignment="Top" Width="135" SelectedDate="{Binding EndDate}"/>
                <ComboBox HorizontalAlignment="Left" Margin="290,31,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Customers}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedValue="{Binding CustomerId}"/>
                <ComboBox HorizontalAlignment="Left" Margin="415,31,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Projects}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedValue="{Binding ProjectId}"/>
                <ComboBox HorizontalAlignment="Left" Margin="540,31,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Services}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedValue="{Binding ServiceId}"/>
                <Button Command="{Binding SearchCommand}" Content="Search" HorizontalAlignment="Left" Margin="665,33,0,0" VerticalAlignment="Top" Width="75"/>
                <Label Content="Customer:" HorizontalAlignment="Left" Margin="290,10,0,0" VerticalAlignment="Top"/>
                <Label Content="Project:" HorizontalAlignment="Left" Margin="415,10,0,0" VerticalAlignment="Top"/>
                <Label Content="Service:" HorizontalAlignment="Left" Margin="540,10,0,0" VerticalAlignment="Top"/>
            </Grid>
        </GroupBox>
        <DataGrid Margin="10,93,9.6,41.4" IsReadOnly="True" ItemsSource="{Binding Results}" AutoGenerateColumns="False" GridLinesVisibility="None">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Date" Binding="{Binding Date, StringFormat={}{0:MMMM dd\, yyyy}}" />
                <DataGridTextColumn Header="Customer" Binding="{Binding Customer}" />
                <DataGridTextColumn Header="Project" Binding="{Binding Project}" />
                <DataGridTextColumn Header="Service" Binding="{Binding Service}" />
                <DataGridTextColumn Header="Note" Binding="{Binding Annotation}" />
                <DataGridTemplateColumn Header="Time">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate DataType="{x:Type colorhatNet:TimeEntry}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding StartTime, StringFormat={}{0:HH\:mm}}"></TextBlock>
                                <TextBlock Text=" - "></TextBlock>
                                <TextBlock Text="{Binding EndTime, StringFormat={}{0:HH\:mm}}"></TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Binding="{Binding Duration}" Header="Duration"/>
            </DataGrid.Columns>
        </DataGrid>
        <StackPanel HorizontalAlignment="Right"  Margin="0,0,9.6,9.4" VerticalAlignment="Bottom" Orientation="Horizontal">
            <Label Content="Total:" HorizontalAlignment="Left" VerticalAlignment="Bottom" VerticalContentAlignment="Bottom"/>
            <TextBlock HorizontalAlignment="Right" TextWrapping="Wrap" Text="{Binding TotalTime}" VerticalAlignment="Top" FontSize="20" Margin="10,0,0,0"/>
        </StackPanel>
        <Button Command="{Binding BreakdownsCommand}" Content="Breakdowns" HorizontalAlignment="Left" Margin="10,0,0,10.4" VerticalAlignment="Bottom" Width="75"/>
        <Button Command="{Binding ExportCommand}" Content="Export" HorizontalAlignment="Left" Margin="90,0,0,10.4" VerticalAlignment="Bottom" Width="75"/>
    </Grid>
</Window>
